<html>

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link href="../../assets/js/common/element/index.css" rel="stylesheet">
	<link href="../../build/common/base.css" rel="stylesheet">
	<script type="text/javascript" src="../../build/common/base.js"></script>
	<script type="text/javascript" src="../../build/common/vueEdit.js"></script>
</head>

<body>
	<div id="ctrl">
		<div class="ibox-title" v-if="isHidden != 'mhclsh'">
			<a class="btn btn-primary fa-save" href="javascript:void(0)" v-on:click="saveData($event)">保存</a>
			<a href="javascript:void(0)" class="btn btn-primary fa-reply" onclick="javascript:$.Dialog.close(window);">返回</a>
		</div>
		<div v-if="loaded">
			<ab-custom-form></ab-custom-form>
		</div>
	</div>
</body>
<script type="text/javascript">
	var vm = new Vue({
		el: "#ctrl",
		data: function () {
			return {
				loaded: false,
				isHidden: ""
			}
		},
		mounted: function () {
			this.isHidden = $.getParam("key")
		},
		beforeCreate: function () {
		},
		methods: {
			saveData: function (e) {
				var errorMsg = Vue.formService.getValidateMsg(this.$children[0]);

				if (errorMsg) {
					$.Dialog.alert("表单校验不通过！" + errorMsg, 7);
					return;
				}
				// 业务校验
				if (this.$children[0].custValid) {
					if (this.$children[0].custValid() === false) {
						return
					}
				}

				var url = Vue.__ctx + "/form/formDefData/saveData?key=" + $.getParam("key") + "&sql=" + $.getParam("sql");
				var post = Vue.baseService.post(url, this.$children[0].$data.data);

				// var active = location.search.replace("?", "").substring(location.search.replace("?", "").length - 5, location.search.replace("?", "").length)
				post.then(function (data) {
					if (data.isOk) {
						if (parent && parent.reloadGrid) {
							parent.reloadGrid();
						}
						//编辑成功显示编辑成功
						// if (localStorage.getItem("btnname") == "发布") {
						// 	avt = "编辑"
						// }
						if (localStorage.getItem("btnname") == "编辑") {
							avt = "修改"
						} else {
							avt = "添加"
						}
						// localStorage.getItem("btnname")
						// console.log("pppppp", localStorage.getItem("btnname"))

						$.Dialog.confirm("提示信息", avt + "成功，是否需要继续添加", function () {
							window.location = window.location;
						}, function () {
							$.Dialog.close(window);
						})
					} else {
						$.Dialog.error(data.msg);
					}

				}, function (e) {
					alert(e);
				});
			}
		},
		created: function () {
			var url = Vue.__ctx + "/form/formDefData/getData";
			var post = Vue.baseService.postForm(url, {
				key: $.getParam("key"),
				id: $.getParam("id"),
				sql: $.getParam("sql"),
			});
			var that = this;
			$.getResultData(post, function (data) {
				window.custFormComponentMixin = {};
				var html = data.html;
				if (window.passData) {// 前端html传过来
					html = window.passData.html;
				}
				Vue.formService.initCustFormFu(html, data);
				that.$data.loaded = true;
			});
		},
		watch: {

		}
	});
</script>

</html>